package com.ruoyi.ybUpload.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.ybUpload.service.upload.YBUploadService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ybUpload.domain.tableCode.TraceCode;
import com.ruoyi.ybUpload.service.tableCode.ITraceCodeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 药品批次表Controller
 *
 * @author wkw
 * @date 2024-08-07
 */
@RestController
@RequestMapping("/ybUpload/traceCode")
public class TraceCodeController extends BaseController
{
    @Autowired
    private ITraceCodeService traceCodeService;
    @Autowired
    private YBUploadService ybUploadService;

//    @GetMapping("/test")
//    public AjaxResult test()
//    {
//        TraceCode traceCode = new TraceCode();
//        traceCode.setYpCode("566240");
//        traceCode.setId(2L);
//        MainForm mainForm = ybUploadService.uploadData(traceCode);
//        return success(mainForm);
//    }

    /**
     * 查询药品批次表列表
     */
    @PreAuthorize("@ss.hasPermi('ybUpload:traceCode:list')")
    @GetMapping("/list")
    public TableDataInfo list(TraceCode traceCode)
    {
        startPage();
        List<TraceCode> list = traceCodeService.selectTraceCodeList(traceCode);
        return getDataTable(list);
    }

    /**
     * 导出药品批次表列表
     */
    @PreAuthorize("@ss.hasPermi('ybUpload:traceCode:export')")
    @Log(title = "药品批次表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TraceCode traceCode)
    {
        List<TraceCode> list = traceCodeService.selectTraceCodeList(traceCode);
        ExcelUtil<TraceCode> util = new ExcelUtil<TraceCode>(TraceCode.class);
        util.exportExcel(response, list, "药品批次表数据");
    }

    /**
     * 获取药品批次表详细信息
     */
    @PreAuthorize("@ss.hasPermi('ybUpload:traceCode:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(traceCodeService.selectTraceCodeById(id));
    }

    /**
     * 新增药品批次表
     */
    @PreAuthorize("@ss.hasPermi('ybUpload:traceCode:add')")
    @Log(title = "药品批次表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TraceCode traceCode)
    {
        return toAjax(traceCodeService.insertTraceCode(traceCode));
    }

    /**
     * 修改药品批次表
     */
    @PreAuthorize("@ss.hasPermi('ybUpload:traceCode:edit')")
    @Log(title = "药品批次表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TraceCode traceCode)
    {
        return toAjax(traceCodeService.updateTraceCode(traceCode));
    }

    /**
     * 删除药品批次表
     */
    @PreAuthorize("@ss.hasPermi('ybUpload:traceCode:remove')")
    @Log(title = "药品批次表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(traceCodeService.deleteTraceCodeByIds(ids));
    }
}
